import { defineConfig } from 'vite'
import { fileURLToPath, URL } from 'node:url'

import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import AutoImport from 'unplugin-auto-import/vite'
import { NaiveUiResolver } from 'unplugin-vue-components/resolvers'
import Components from 'unplugin-vue-components/vite'

// https://vite.dev/config/
export default defineConfig({
    base: '/c12100',
    server: {
        host: true, // 监听所有地址
        port: 5173, //指定开发服务器端口
        open: false, //启动时自动在浏览器中打开
        cors: true, //为开发服务器配置 CORS
        strictPort: true, // 若端口被占用,直接结束项目
        proxy: {
            //配置自定义代理规则
            '/c12100/axios/': 'http://127.0.0.1:12100',
            '/gitee': {
                target: 'https://gitee.com',
                changeOrigin: true,
                rewrite: (path: string) => path.replace(/^\/gitee/, ''),
                secure: true,
                timeout: 5000,
                ws: false
            }
        }
    },

    plugins: [
        vue(),
        vueDevTools(),
        AutoImport({
            imports: [
                'vue',
                {
                    'naive-ui': ['useDialog', 'useMessage', 'useNotification', 'useLoadingBar']
                }
            ]
        }),
        Components({
            resolvers: [NaiveUiResolver()]
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./WebFrontend', import.meta.url))
        }
    },
    build: {
        target: 'es2020', //指定es版本,浏览器的兼容性
        outDir: 'sea-archiver/WebApp', //指定打包输出路径
        //assetsDir: "static",  //指定静态资源存放路径
        cssCodeSplit: true, //css代码拆分,禁用则所有样式保存在一个css里面
        sourcemap: false //是否构建source map 文件
        //minify: 'terser', //需要npm install terser
        //terserOptions: {  //需要npm install terser
        //  compress: {
        //    drop_console: true, //编译移除console
        //    drop_debugger: true,  //编译移除debugger
        //  },
        //},
    }
})
